#ifndef P2PBrokerI_H
#define P2PBrokerI_H

#include <Ice/Ice.h>
#include <IceUtil/Mutex.h>
#include <Yafridng.h>
#include <Controller.h>

using namespace std;
using namespace Yafridng;

typedef struct
{
  int piece;
  FileStorePrx fileStore;
}PieceInfo;
class P2PBrokerI : public P2PBroker, public IceUtil::Mutex
{
 public:
  P2PBrokerI(string fileName, 
	     ::Yafridng::FileStorePrx& myFileStore,
	     ::Yafridng::Pieces& pieces,
	     Controller *c);

  virtual void notifyPiece(const ::Ice::Int piece,
			   const ::Yafridng::FileStorePrx& fileSt,
			   const ::Ice::Current&);
  
  virtual ::Yafridng::FilePrx getPieceKeeper(const ::Ice::Int piece,
					     /*const ::std::string& nodeId,*/
					     const ::Ice::Current&);
 private:
  string _fileName;
  int _num;
  FileStorePrx _myFileStore;
  Pieces _pieces;
  vector<PieceInfo> availablePieces;
  Controller *_control;
};
#endif
